package com.zijidelu.luframework.base.message.impl;

import com.zijidelu.luframework.base.message.Message;

/**
 * 通用消息枚举。
 *
 * @author ZIJIDELU
 * @datetime 2025/4/5 21:47
 */
public enum GenericMessage implements Message {
    SUCCESS(true, 1, "成功"),
    BIZ_EXCEPTION(false, 0, "失败"),
    SYS_EXCEPTION(false, -1, "系统异常"),
    ;

    private final boolean success;
    private final int code;
    private final String message;

    GenericMessage(boolean isSuccess, int code, String text) {
        this.success = isSuccess;
        this.code = code;
        this.message = text;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getText() {
        return message;
    }

    @Override
    public boolean isSuccess() {
        return success;
    }

    /**
     * 根据是否成功获取消息。
     *
     * @param isSuccess 是否成功
     * @return 消息
     */
    public static GenericMessage of(boolean isSuccess) {
        return isSuccess ? SUCCESS : BIZ_EXCEPTION;
    }
}
